<template>
    <d2-container type="card">
        <header>
            <el-form :inline="true" :model="selectFrom" class="demo-form-inline" size="mini">
                <el-form-item label="配送员名称">
                    <el-input v-model="selectFrom.name" placeholder="配送员名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="getDeliveryExamineData()">查询</el-button>
                </el-form-item>
            </el-form>
        </header>
        <footer>
            <el-table :data="tableData" border style="width: 100%" size="mini" :height="height"
                @expand-change="expandChange" :expand-row-keys="expands" :row-key="getRowKeys">
                <el-table-column type="expand" label="配送员信息" align="center" width="100">
                    <template slot-scope="scope">
                        <el-descriptions :title="scope.row.deliveryInfo.name" :column="4" border>
                            <el-descriptions-item label="配送员">{{ scope.row.deliveryInfo.name }}</el-descriptions-item>
                            <el-descriptions-item label="手机号">{{ scope.row.deliveryInfo.phone }}</el-descriptions-item>
                            <el-descriptions-item label="性别">
                                <div v-if="scope.row.deliveryInfo.sex == 0">女</div>
                                <div v-if="scope.row.deliveryInfo.sex == 1">男</div>
                            </el-descriptions-item>
                            <el-descriptions-item label="所属校区">
                                {{ scope.row.deliveryInfo.comSchool.name }}
                            </el-descriptions-item>
                        </el-descriptions>
                    </template>
                </el-table-column>
                <el-table-column prop="id" label="审核ID" align="center">
                </el-table-column>
                <el-table-column prop="isExamine" label="是否审核" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.isExamine == 0">未审核</div>
                        <div v-if="scope.row.isExamine == 1">已审核</div>
                    </template>
                </el-table-column>
                <el-table-column prop="isPass" label="是否通过" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.isPass == 0">未通过</div>
                        <div v-if="scope.row.isPass == 1">已通过</div>
                    </template>
                </el-table-column>
                <el-table-column prop="adminId" label="管理员ID" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.comAdmin">{{ scope.row.comAdmin.name }}</div>
                        <div v-else>无</div>
                    </template>
                </el-table-column>
                <el-table-column prop="auditTime" label="审核时间" align="center">
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间" align="center">
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="examineFunction(scope.row)"
                            v-if="scope.row.isExamine == 0">审核</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="block" style="text-align:center">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
                    :page-sizes="[5, 10, 15, 20]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                </el-pagination>
            </div>
        </footer>
        <el-dialog title="审核" :visible.sync="examineSign" width="30%" :close-on-click-modal="false"
            :close-on-press-escape="false" :show-close="false">
            <el-form ref="examineform" :model="examineform" label-width="80px" :rules="rules">
                <el-form-item label="审核理由">
                    <el-input type="textarea" v-model="examineform.reason" maxlength="100" show-word-limit></el-input>
                </el-form-item>
                <el-form-item label="审核状态" prop="isPass">
                    <el-radio-group v-model="examineform.isPass" size="mini">
                        <el-radio-button :label="0">驳回</el-radio-button>
                        <el-radio-button :label="1">通过</el-radio-button>
                    </el-radio-group>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="closeExamineFunction()" size="mini">取 消</el-button>
                <el-button type="primary" @click="examineData()" size="mini">确 定</el-button>
            </span>
        </el-dialog>
    </d2-container>
</template>
  
<script>
import { getDeliveryExamine, updateDeliveryExamine } from "@/api/modules/delivery_examine.js"
export default {
    name: 'shopInfo',
    data() {
        return {
            selectFrom: {},//搜索栏
            tableData: [],//表格数据
            page: 1,
            limit: 10,
            total: 0,
            height: window.innerHeight - 250, //表格高度
            expands: [], //只展开一行放入当前行id
            getRowKeys(row) {
                return row.id;
            },
            examineSign: false,
            examineform: {},//审核表单
            rules: {
                isPass: [{ required: true, message: '请选择审核方式', trigger: 'change' }]
            },
            selectRowFrom: {},//选中
        }
    },
    mounted() {
        this.getDeliveryExamineData();
        //-------------------------表格响应----------------//
        this.createHeight();
        //当页面发生变化时，表格高度固定
        window.onresize = () => {
            return (() => {
                this.$nextTick(() => {
                    this.createHeight();
                });
            })();
        };
    },
    methods: {
        //注册
        examineFunction(row) {
            this.examineSign = true;
            this.selectRowFrom = JSON.parse(JSON.stringify(row));
        },
        //获取配送员数据
        getDeliveryExamineData() {
            this.selectFrom.page = this.page;
            this.selectFrom.limit = this.limit;
            getDeliveryExamine(this.selectFrom).then(res => {
                this.tableData = res.dataList;
                this.total = res.total;
            })
        },
        closeExamineFunction() {
            this.examineSign = false;
            this.cleanExamineFunction();
        },
        cleanExamineFunction() {
            this.examineform = {};
            if (this.$refs['examineform']) {
                this.$refs['examineform'].resetFields();
            }
        },
        //表格当前行被展开或收起
        expandChange(row, expandedRows) {
            let that = this;
            //只展开一行
            if (expandedRows.length) {
                //说明展开了
                that.expands = [];
                if (row) {
                    that.expands.push(row.id); //只展开当前行id
                }
            } else {
                //说明收起了
                that.expands = [];
            }
        },
        //提交
        examineData() {
            this.$refs['examineform'].validate((valid) => {
                if (valid) {
                    this.selectRowFrom.reason = this.examineform.reason;
                    this.selectRowFrom.isPass = this.examineform.isPass;
                    this.selectRowFrom.isExamine = 1;
                    updateDeliveryExamine(this.selectRowFrom).then(res => {
                        this.getDeliveryExamineData();
                        this.closeExamineFunction();
                    })
                } else {
                    return false;
                }
            });
        },
        handleSizeChange(val) {
            this.limit = val;
            this.getDeliveryInfoData();
        },
        handleCurrentChange(val) {
            this.page = val;
            this.getDeliveryInfoData();
        },
        //---------------自动变更表格高度------------------//
        createHeight() {
            this.height = window.innerHeight - 250;
        }
    }
}
</script>
  